package org.daochong.fastdev.funcs;

import java.sql.SQLException;

import org.daochong.fastdev.Context;
import org.daochong.fastdev.Function;
import org.daochong.fastdev.OperationId;
import org.daochong.fastdev.util.FastDevUtils;
import org.daochong.lang.BeanUtil;
import org.daochong.lang.StringUtils;

public class ObjectFunction implements Function {

	public boolean is(String id) {
		return FastDevUtils.operNumber("object", id);
	}

	public void exec(String key, String prop, Context context)  throws SQLException{
		if (!is(key))
			throw new RuntimeException("Function  not match [" + key + "]");
		prop = BeanUtil.formatString(prop, context);
		if (StringUtils.isEmpty(prop))
			return;
		for (OperationId oid : FastDevUtils.operationIds(prop)) {
			Object obj = context.getJdbcOperations().get(oid.getId(), context.getParameters());
			context.add(oid, obj);
		}
	}

}
